package com.tech.platform.cms.databases.mybatis.sqlParser.handler;

import com.baomidou.mybatisplus.extension.parsers.ITableNameHandler;
import org.apache.ibatis.reflection.MetaObject;

/**
 * @author shengqiang.wu
 * @date 2019/12/30/030 18:29
 * @desc
 */
public abstract class AbstractDynamicTableHandler implements ITableNameHandler{

    public abstract String fetAppendTablePart();

    public abstract boolean doFilterTable(String tableName);

    @Override
    public String process(MetaObject metaObject, String sql, String tableName) {
        String dynamicTableName = dynamicTableName(metaObject, sql, tableName);
        if (null != dynamicTableName && !dynamicTableName.equalsIgnoreCase(tableName)) {
            return sql.replaceAll(tableName, dynamicTableName);
        }
        return sql;
    }

}
